#pragma once

#include "Interaction.h"

#include "Action.h"
#include "Gate.h"
#include "InteractionFragment.h"
#include "Lifeline.h"
#include "Message.h"

namespace uml {

Interaction::Interaction(const QString& umlType)
    : Behavior(umlType) {}

void Interaction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    InteractionFragment::fromJson(json, errorList);
    Behavior::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(actions_, "actions", json, errorList);
    JsonSerializable::fromJsonArray(formalGates_, "formalGates", json, errorList);
    JsonSerializable::fromJsonArray(fragments_, "fragments", json, errorList);
    JsonSerializable::fromJsonArray(lifelines_, "lifelines", json, errorList);
    JsonSerializable::fromJsonArray(messages_, "messages", json, errorList);
}

void Interaction::toJson(QJsonObject& json) {
    InteractionFragment::toJson(json);
    Behavior::toJson(json);
    JsonSerializable::toJsonArray(actions_, "actions", json);
    JsonSerializable::toJsonArray(formalGates_, "formalGates", json);
    JsonSerializable::toJsonArray(fragments_, "fragments", json);
    JsonSerializable::toJsonArray(lifelines_, "lifelines", json);
    JsonSerializable::toJsonArray(messages_, "messages", json);
}

/// <summary>
/// actions getter
/// Actions owned by the Interaction.
/// </summary>
vector<shared_ptr<Action>>& Interaction::actions() {
    return actions_;
}

/// <summary>
/// formalGates getter
/// Specifies the gates that form the message interface between this Interaction and
/// any InteractionUses which reference it.
/// </summary>
vector<shared_ptr<Gate>>& Interaction::formalGates() {
    return formalGates_;
}

/// <summary>
/// fragments getter
/// The ordered set of fragments in the Interaction.
/// </summary>
vector<shared_ptr<InteractionFragment>>& Interaction::fragments() {
    return fragments_;
}

/// <summary>
/// lifelines getter
/// Specifies the participants in this Interaction.
/// </summary>
vector<shared_ptr<Lifeline>>& Interaction::lifelines() {
    return lifelines_;
}

/// <summary>
/// messages getter
/// The Messages contained in this Interaction.
/// </summary>
vector<shared_ptr<Message>>& Interaction::messages() {
    return messages_;
}

} // namespace uml
